package demo.utils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

@Slf4j
public class RedisUtil {

    StringRedisTemplate template;

    private Long day = 1L;

    public RedisUtil(StringRedisTemplate template) {
        this.template = template;
    }

    public boolean set(String key, String value) {
        template.opsForValue().set(key, value, day, TimeUnit.DAYS);
        return true;
    }

    public boolean set(String key, String value, Long seconds) {
        template.opsForValue().set(key, value, seconds, TimeUnit.SECONDS);
        return true;
    }

    public String get(String key) {
        return template.opsForValue().get(key);
    }

    public boolean delete(String key) {
        template.delete(key);
        return true;
    }

    public boolean hasKey(String key) {
        return template.hasKey(key);
    }
}
